<template>
  <div class="">
    <div style="text-align: center;margin-top: 30px">
      <el-image
        style="width: 200px; height: 200px"
        src="/static/商品活动.png"
        :fit="fit"></el-image>
    </div>
    <van-search size="xx-large" v-model="user.username" shape="round"
                placeholder="请输入用户名"
                :left-icon="customIcon"
    />
    <div class="search-container">
      <van-search
        size="xx-large"
        v-model="user.password"
        shape="round"
        type="password"
        placeholder="请输入密码"
        :left-icon="customIcon2"
        ref="search"
      />
<!--      <button class="search-button" @click="sendVerificationCode">-->
<!--        发送验证码-->
<!--      </button>-->
    </div>
    <div style="padding: 10px">
    <van-button style="height: 60px;font-size: 18px;width: 100%;" round type="info" @click="onSubmit">登录</van-button></div>
    <div style="text-align: center;cursor: pointer" @click="turnto">没有有账号，去注册！</div>
  </div>
</template>

<script>
import Vue from 'vue';
import {Form, Toast} from 'vant';
import { Field } from 'vant';
import { Button } from 'vant';
import request from "../../utils/request";
import {setRoutes} from "../../router";
import { Search } from 'vant';
import { Cell } from 'vant';

Vue.use(Cell);
Vue.use(Search);
Vue.use(Button);
Vue.use(Form);
Vue.use(Field);
export default {
data(){
  return{
    customIcon: 'manager',
    customIcon2: 'lock',
    show:true,
    //      注册数据
    register:{},
//        登录数据
    user:{},
    checked:false,
  }
},
  methods: {
    turnto(){
      this.$router.push('/appregister')
    },
    //登录
    onSubmit() {
      let url = '/login/user'
      request.post(url, this.user).then(resp => {
        if (resp.code === 200) {
          console.log(resp.msg)
          localStorage.setItem("token", resp.host)
          localStorage.setItem("menus", JSON.stringify(resp.data))
          localStorage.setItem("user", JSON.stringify(resp.msg.user))
          localStorage.setItem("permissions", JSON.stringify(resp.msg.permissions))
          setRoutes()
          this.$router.push('/apphome')
          Toast.success(resp.errorMessage);
          this.loading = false
        }else {
          Toast.fail(resp.errorMessage);
        }
      })
    },
  }

  }
</script>

<style scoped>
>>> .van-cell{
  font-size: 16px;
  line-height: 50px;
}
.search-container {
  position: relative;
}
.search-button {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translate(0, -50%);
  background-color: red;
  color: #fff;
  border: none;
  border-radius: 10px 25px 25px 10px;
  padding: 8px 12px;
  height: 54px;
  font-size: 16px;
  cursor: pointer;
}
</style>
